﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Data;
using System.Globalization;
using TrainingDB.Model;


namespace Cls_Business
{
    public delegate void ShowWindow(object sender, MyEventArgs e);

    public class MyEventArgs : EventArgs         //定义事件参数类
    {
        public readonly string _strName;
        public MyEventArgs(string strName)
        {
            this._strName = strName;
        }
    }

    public class GlobalControl
    {
        private static GlobalControl m_GlobalControl = null;
        public static int m_nLoginUserId = 0;
        private static TrainingDB.BLL.CK_OperLogTab m_bllDG_OperLogTab = new TrainingDB.BLL.CK_OperLogTab();
        private static List<T_ACL_Function> m_UserFunList = new List<T_ACL_Function>();
        private static TrainingDB.BLL.T_ACL_Function m_bllT_ACL_Function = new TrainingDB.BLL.T_ACL_Function();
        public event ShowWindow OnShowWindow;         //定义事件，将其与代理绑定

        public void FireEvent(MyEventArgs e)       //触发事件的方法
        {
            if (OnShowWindow != null)
            {
                OnShowWindow(this, e);      //触发事件
            }
        }

        public static GlobalControl GetGlobalControl()
        {
            if (m_GlobalControl == null)
            {
                m_GlobalControl = new GlobalControl();
                m_UserFunList = m_bllT_ACL_Function.GetFunctionsByUser(GlobalControl.m_nLoginUserId);

            }

            return m_GlobalControl;
        }

        public static void Log2DB(string strModuleName, string strOperName, string DanjuNameOrNo)
        {
            TrainingDB.Model.CK_OperLogTab modelCK_OperLogTab = new TrainingDB.Model.CK_OperLogTab();
            modelCK_OperLogTab.CK_OperDate = System.DateTime.Now;
            modelCK_OperLogTab.CK_OperUserID = m_nLoginUserId;
            modelCK_OperLogTab.CK_OperName = strOperName;
            modelCK_OperLogTab.CK_ModuleName = strModuleName;
            modelCK_OperLogTab.CK_DanjuNameOrNo = DanjuNameOrNo;

            m_bllDG_OperLogTab.Add(modelCK_OperLogTab);
        }

        public static bool CheckPerm(string strModuleName, string strOperName)
        {
            bool bRet = false;
            string strTemp = strModuleName + "_" + strOperName;
            foreach (T_ACL_Function f in m_UserFunList)
            {
                if (f.Name.Equals(strTemp))
                {
                    bRet = true;
                    break;
                }
            }
            return bRet;
        }
    }
}
